package com.sunjy.common.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by zhouyao on 2017/11/9.
 */
public class CheckUtils {
    private CheckUtils() {}

    /**
     * 检查是否为正金额且小数最多10位
     * @param money
     * @return true满足规则  false不满足规则
     */
    public static boolean isMoneyDecimal10Most(String money){
        return matches("^[0-9]+$|^[0-9]+\\.[0-9]{1,10}$",money);
    }

    /**
     * 校验年月是否2打头且4位数字-月必须为2位
     * @param yearMonth
     * @return
     */
    public static boolean checkYearMonth(String yearMonth) {
        return matches("(^[2]\\d{3})+-(0[1-9]|1[0-2])$",yearMonth);
    }

    private static boolean matches(String pattern,String str){
        Pattern p = Pattern.compile(pattern);
        Matcher m = p.matcher(str);
        return m.matches();
    }
}
